package sjtu.ist.warehouse4ws.action;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import sjtu.ist.warehouse4ws.model.GroupCompany;
import sjtu.ist.warehouse4ws.model.Modelgroup;
import sjtu.ist.warehouse4ws.service.GroupCompanyService;
import sjtu.ist.warehouse4ws.service.ModelgroupService;
import sjtu.ist.warehouse4ws.vo.ModelgroupVO;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.apache.struts2.json.annotations.JSON;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class CompanyModelgroupAction extends ActionSupport{
	private ModelgroupService modelgroupService;
	private GroupCompanyService groupCompanyService;
	private List<ModelgroupVO> modelgroupVoList = new ArrayList<ModelgroupVO>();
	
	private String id;
	
	private boolean success=true;
	
	private int start;
	private int limit;
	private int count;

	
	//获得Privilege列表
	public String showCompanyModelgroupList(){
		Subject currentUser = SecurityUtils.getSubject();		
		Integer userCompany=(Integer) currentUser.getSession().getAttribute("companyId");
		
		List<ModelgroupVO> mlist=modelgroupService.getAllByAdmin();
		List<GroupCompany> gclist=groupCompanyService.getGroupCompanyList();
		for(int i=0;i<mlist.size();i++){
			ModelgroupVO mg=mlist.get(i);
			ModelgroupVO vo=new ModelgroupVO(mg.getId(),mg.getGroupName(),mg.getDescription(),0,mg.getVersion());
			vo.setStatus(0);
			for(int j=0;j<gclist.size();j++){
				GroupCompany gc=gclist.get(j);
				if(mg.getId()==gc.getGroupId()){
					vo.setStatus(gc.getStatus());					
					break;
				}
			}
			modelgroupVoList.add(vo);
		}
		return SUCCESS;
	}
	
	@JSON(name = "totalModelgroupVO")
	public int getModelgroupVo() {
		return this.modelgroupVoList.size();
		//return count;
	}
	
	@JSON(name = "ModelgroupVO")
	public List<ModelgroupVO> getModelgroupVoList() {
		return modelgroupVoList;
	}
	
	public void setId(String id) {
		this.id = id;
	}

	@JSON(name = "success")
	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public void setModelgroupService(ModelgroupService modelgroupService) {
		this.modelgroupService = modelgroupService;
	}

	public void setGroupCompanyService(GroupCompanyService groupCompanyService) {
		this.groupCompanyService = groupCompanyService;
	}
	
	public void setModelgroupVoList(List<ModelgroupVO> modelgroupVoList) {
		this.modelgroupVoList = modelgroupVoList;
	}
	
	
}